In Kanzi you can create keyframe animations that:
You can create the animation data for keyframe animations in these ways:
To create keyframe animations using the Kanzi Engine API, see Creating animations and timelines using the Kanzi Engine API.
To create a keyframe animation for node properties:
To create a keyframe animation for a target property attribute:
To create a keyframe animation:
// Create a float keyframe animation. FloatKeyframeAnimationSharedPtr keyframeAnimation = FloatKeyframeAnimation::create(domain); // Create and add keyframes to the keyframe animation. This keyframe animation contains two linear keyframes. // Create a linear keyframe at second 0 with the value 0. keyframeAnimation->addLinearKeyframe(chrono::seconds::zero(), 0.0f); // Create a linear keyframe at second 1 with the value 100. keyframeAnimation->addLinearKeyframe(chrono::seconds(1), 100.0f);
To animate a property value in a node using a keyframe animation:
// Create a property timeline and apply the keyframeAnimation keyframe animation to the Layout Width property // to animate the width of the current node. PropertyAnimationTimelineSharedPtr propertyTimeline = PropertyAnimationTimeline::create(domain, ".", Node2D::WidthProperty, keyframeAnimation);
To animate a property field value in a node using a keyframe animation:
// Create a property field animation timeline and apply it to the Render Transformation property of the current node. PropertyFieldAnimationTimelineSharedPtr propertyFieldTimeline = PropertyFieldAnimationTimeline::create(domain, ".", Node2D::RenderTransformationProperty); // Rotate the current node by animating the Rotation Z property field of the Render Transformation property // with the keyframeAnimation keyframe animation. propertyFieldTimeline->addEntry(PropertyFieldRotationZ, keyframeAnimation);
To create a keyframe animation that uses Bezier keyframes to move an object on a sideways figure eight shaped path:
// Create two float keyframe animations: one to animate the object on the x axis, // the other to animate the object on the y axis. // Create float keyframe animation keyframeAnimationX that uses linear keyframes // to animate the movement of the object on the x axis. FloatKeyframeAnimationSharedPtr keyframeAnimationX = FloatKeyframeAnimation::create(domain); // Create a linear keyframe at second 0 with the value 0. keyframeAnimationX->addLinearKeyframe(chrono::seconds::zero(), 0.0f); // Create a linear keyframe at second 4 with the value 4. // At this keyframe the object reaches the furthest point on the x axis. keyframeAnimationX->addLinearKeyframe(chrono::seconds(4), 4.0f); // Create a linear keyframe at second 8 with the value 0. // At this keyframe the object returns to the same position it had at the first keyframe. keyframeAnimationX->addLinearKeyframe(chrono::seconds(8), 0.0f); // Create float keyframe animation keyframeAnimationY that uses Bezier keyframes // to animate the movement of the object on the y axis. FloatKeyframeAnimationSharedPtr keyframeAnimationY = FloatKeyframeAnimation::create(domain); // Create a linear keyframe at second 0 with the value 0. When you use Bezier keyframes, // you can use any type of keyframe for the first keyframe, because you need this keyframe // only to provide the information for the starting position. keyframeAnimationY->addLinearKeyframe(chrono::seconds::zero(), 0.0f); // Create a Bezier keyframe at second 4 with the value 0 and two control points. // You use the control points to set the position of the keyframe. keyframeAnimationY->addBezierKeyframe(chrono::seconds(4), 0.0f, Vector2(0.5f, 4.0f), Vector2(0.5f, -4.0f)); // Create a Bezier keyframe at second 8 with the value 0 and two control points. // This keyframe uses the same control points, but because the keyframeAnimationX // animation moves the object on the x axis back to its starting position, this keyframe // is a mirror image of the previous keyframe. keyframeAnimationY->addBezierKeyframe(chrono::seconds(8), 0.0f, Vector2(0.5f, 4.0f), Vector2(0.5f, -4.0f)); // Create a property field animation timeline and apply it to the Render Transformation property of the current node. PropertyFieldAnimationTimelineSharedPtr timeline = PropertyFieldAnimationTimeline::create(domain, ".", Node3D::RenderTransformationProperty); // Move the current node on the x axis by animating the Translation X property field of the Render Transformation property // with the keyframeAnimationX keyframe animation. timeline->addEntry(PropertyFieldTranslationX, keyframeAnimationX); // Move the current node on the y axis by animating the Translation Y property field of the Render Transformation property // with the keyframeAnimationY keyframe animation. timeline->addEntry(PropertyFieldTranslationY, keyframeAnimationY);
To play an animation regardless of the timeline type:
// Create the playback context and the timeline playback for the node defined in the item2d. SceneGraphTimelinePlaybackContext context(*item2d); // Create the playback for the timeline defined in the propertyFieldTimeline. TimelinePlaybackSharedPtr playback = propertyFieldTimeline->createPlayback(context); // Start the animation. domain->getRootTimelineClock()->addTimelinePlayback(playback);
For details, see the KeyframeAnimation
class in the API reference.
Changing the interpolation mode between keyframes
Tutorial: Create keyframe animations
Creating animations and timelines using the Kanzi Engine API